package com.lungle.warmdiary.app.view.message.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lungle.warmdiary.R;
import com.lungle.warmdiary.app.base.ListBaseAdapter;
import com.lungle.warmdiary.app.model.response.Message;
import com.lungle.warmdiary.app.utils.DateUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MessageAdapter extends ListBaseAdapter {


    @Override
    protected View getRealView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.list_cell_message, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        Message item = (Message) mDatas.get(position);
        if (item.getType() == Message.TYPE_SYSTEM) {
            vh.mIvTip.setImageResource(R.drawable.ic_message_system);
        } else {
            vh.mIvTip.setImageResource(R.drawable.ic_message_notice);
        }

        if (item.getStatus() == Message.STATE_READ) {
            vh.mIvMessateState.setVisibility(View.INVISIBLE);

        } else {
            vh.mIvMessateState.setVisibility(View.VISIBLE);
        }


        vh.mTvMessageTitle.setText(item.getTitle());
        vh.mTvMessageSummary.setText(item.getContent());


        String date = DateUtil.getFormatTime(item.getCreatetime());
        vh.mTvMessageDate.setText(date);

        return convertView;
    }



    static class ViewHolder {
        @Bind(R.id.iv_tip)
        ImageView mIvTip;
        @Bind(R.id.tv_active_title)
        TextView mTvMessageTitle;
        @Bind(R.id.iv_messate_state)
        ImageView mIvMessateState;
        @Bind(R.id.tv_message_date)
        TextView mTvMessageDate;
        @Bind(R.id.tv_message_summary)
        TextView mTvMessageSummary;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
